package com.gulimall.member.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.common.to.MemberAddressTo;
import com.gulimall.member.service.impl.MemberReceiveAddressServiceImpl;
import org.springframework.web.bind.annotation.*;

import com.gulimall.member.entity.MemberReceiveAddressEntity;
import com.common.utils.PageUtils;
import com.common.utils.R;

import javax.annotation.Resource;


/**
 * 会员收货地址
 *
 * @author Rookie-886
 * @email ${email}
 * @date 2021-03-14 22:25:33
 */
@RestController
@RequestMapping("member/memberreceiveaddress")
public class MemberReceiveAddressController {
    @Resource
    private MemberReceiveAddressServiceImpl memberReceiveAddressServiceImpl;

    /**
     * 列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("member:memberreceiveaddress:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = memberReceiveAddressServiceImpl.queryPage(params);

        return R.ok().put("page", page);
    }

    @GetMapping("/getFare")
    public R getFare(@RequestParam Long addressId){
        return R.ok().put("data",memberReceiveAddressServiceImpl.getFare(addressId));
    }

    @GetMapping("/getAddressList")
    public R getAddressListByUserId(@RequestParam Long userId){
        List<MemberAddressTo> memberAddressToList = memberReceiveAddressServiceImpl.getAddressListByUserId(userId);
        return R.ok().put("data",memberAddressToList);
    }



    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("member:memberreceiveaddress:info")
    public R info(@PathVariable("id") Long id){
		MemberReceiveAddressEntity memberReceiveAddress = memberReceiveAddressServiceImpl.getById(id);

        return R.ok().put("memberReceiveAddress", memberReceiveAddress);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
//    @RequiresPermissions("member:memberreceiveaddress:save")
    public R save(@RequestBody MemberReceiveAddressEntity memberReceiveAddress){
        memberReceiveAddressServiceImpl.save(memberReceiveAddress);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
//    @RequiresPermissions("member:memberreceiveaddress:update")
    public R update(@RequestBody MemberReceiveAddressEntity memberReceiveAddress){
        memberReceiveAddressServiceImpl.updateById(memberReceiveAddress);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
//    @RequiresPermissions("member:memberreceiveaddress:delete")
    public R delete(@RequestBody Long[] ids){
        memberReceiveAddressServiceImpl.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
